<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta
            property="og:title"
            content="Disk Scheduling Algorithm Visualization"
        />
        <meta
            property="og:description"
            content="Disk Scheduling Algorithm Visualization"
        />
        <meta
            property="og:image"
            content="https://proxy.xixu.us.kg/?url=https%3A%2F%2Fxi-xu.me%2Fimages%2Ffavicon.png"
        />
        <meta property="og:url" content="https://os.xixu.us.kg" />
        <meta
            name="description"
            content="Disk Scheduling Algorithm Visualization"
        />
        <meta
            name="keywords"
            content="Disk Scheduling Algorithm Visualization"
        />
        <title>Disk Scheduling Algorithm Visualization</title>
        <link
            rel="icon"
            href="https://proxy.xixu.us.kg/?url=https%3A%2F%2Fxi-xu.me%2Fimages%2Ffavicon.png"
            type="image/png"
        />
        <link rel="stylesheet" href="styles.css" />
    </head>
    <body>
        <div class="container">
            <h1>Disk Scheduling Algorithm Visualization</h1>

            <div class="controls">
                <div class="input-row">
                    <label>Initial Head Position:</label>
                    <input
                        type="number"
                        id="initialHead"
                        value="70"
                        min="0"
                        max="199"
                    />

                    <label>Request Queue:</label>
                    <input
                        type="text"
                        id="requestQueue"
                        value="82,170,43,140,24,16,190"
                        placeholder="Comma-separated numbers"
                    />
                </div>

                <div class="buttons-row">
                    <button onclick="reset()">Reset</button>
                    <button onclick="startFCFS()">Start FCFS</button>
                    <button onclick="startSSTF()">Start SSTF</button>
                    <button onclick="startSCAN()">Start SCAN</button>
                    <label>SCAN Direction:</label>
                    <select id="scanDirection">
                        <option value="right">Right</option>
                        <option value="left">Left</option>
                    </select>
                </div>
            </div>

            <div class="disk-track" id="diskTrack">
                <div class="head" id="head"></div>
                <div class="track-scale">
                    <span>0</span>
                    <span>50</span>
                    <span>100</span>
                    <span>150</span>
                    <span>199</span>
                </div>
            </div>

            <div id="stats">
                <div class="stat-item">
                    <span>Total Seek Time:</span>
                    <span class="stat-value" id="seekTime">0</span>
                </div>
                <div class="stat-item">
                    <span>Current Position:</span>
                    <span class="stat-value" id="currentPos">0</span>
                </div>
            </div>

            <div class="seek-time-comparison">
                <table id="comparisonTable">
                    <thead>
                        <tr>
                            <th>Algorithm</th>
                            <th>Total Seek Time</th>
                            <th>Execution Order</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr id="fcfsRow">
                            <td>FCFS</td>
                            <td>-</td>
                            <td>-</td>
                        </tr>
                        <tr id="sstfRow">
                            <td>SSTF</td>
                            <td>-</td>
                            <td>-</td>
                        </tr>
                        <tr id="scanRow">
                            <td>SCAN</td>
                            <td>-</td>
                            <td>-</td>
                        </tr>
                    </tbody>
                </table>
                <div class="comparison-footer">
                    <button
                        onclick="resetComparisonTable()"
                        class="reset-table-btn"
                    >
                        Reset Table
                    </button>
                </div>
            </div>

            <details class="algorithm-comparison">
                <summary>Algorithm Characteristics Comparison</summary>
                <div class="comparison-content">
                    <div class="algorithm-card">
                        <h3>FCFS (First Come First Serve)</h3>
                        <ul>
                            <li>Serves requests in order of arrival</li>
                            <li>Simple implementation, fair</li>
                            <li>
                                Poor performance, may cause frequent
                                long-distance head movements
                            </li>
                            <li>No starvation</li>
                        </ul>
                    </div>
                    <div class="algorithm-card">
                        <h3>SSTF (Shortest Seek Time First)</h3>
                        <ul>
                            <li>
                                Prioritizes closest requests to current head
                                position
                            </li>
                            <li>Lower average seek time</li>
                            <li>May cause starvation for distant requests</li>
                            <li>Excellent local performance</li>
                        </ul>
                    </div>
                    <div class="algorithm-card">
                        <h3>SCAN (Elevator Algorithm)</h3>
                        <ul>
                            <li>
                                Moves in one direction until end, then reverses
                            </li>
                            <li>Prevents starvation</li>
                            <li>Fair for bidirectional disk access</li>
                            <li>Performance between FCFS and SSTF</li>
                        </ul>
                    </div>
                </div>
            </details>

            <footer class="copyright">
                <p>
                    View source code on
                    <a href="https://github.com/xixu-me/disk-scheduling"
                        >GitHub</a
                    >
                </p>
            </footer>
        </div>
        <script src="script.js"></script>
    </body>
</html>
